import os
from PIL import Image

if __name__ == '__main__':
    path = input("请将图片拖入此窗口：")
    row = int(input("请输入切片行数："))
    if not os.path.exists('图片切片'):
        os.mkdir('图片切片')
    img = Image.open(path)
    width, hight = img.size
    num = 1
    row_higth = 0
    for i in range(row):
        print("正在保存第%d张" % num)
        img.crop((0, row_higth, width, hight // row * num)).save("图片切片/%s.png" % num, "PNG")
        row_higth = row_higth + hight // row
        num = num + 1
